//
//  BaseViewController.m
//  KEREN
//
//  Created by MW on 2023/3/8.
//

#import "BaseViewController.h"

@interface BaseViewController ()
@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = Main_BackColor;
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    // Do any additional setup after loading the view.
}

- (void)setNavViewWithRightTitle:(NSString *)rightTitle navColorIswhite:(BOOL)isWhite withTitle:(NSString *)title{
    _navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, 56 + STATUSBAR_HEIGHT)];
    [self.view addSubview:_navView];
    UIButton *backBtn = [[UIButton alloc] init];
    [_navView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.top.offset(8 + STATUSBAR_HEIGHT);
        make.width.height.offset(40);
    }];
    
    _titleLbl = [[UILabel alloc] init];
    [_navView addSubview:_titleLbl];
    _titleLbl.text = title;
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(backBtn);
        make.left.offset(64);
        make.right.offset(-64);
    }];
    _titleLbl.textAlignment = NSTextAlignmentCenter;
    _titleLbl.font = BFont(20);
    if(isWhite){
        _titleLbl.textColor = Black_Color;
        _navView.backgroundColor = [UIColor whiteColor];
        [backBtn setImage:[UIImage imageNamed:@"main_back"] forState:UIControlStateNormal];
    }else{
        _titleLbl.textColor = Whire_Color;
        _navView.backgroundColor = [UIColor clearColor];
        [backBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
    }
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    if(rightTitle.length > 0){
        _rightLbl = [[UILabel alloc] init];
        [_navView addSubview:_rightLbl];
        [_rightLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-20);
            make.centerY.equalTo(_titleLbl);
            make.height.offset(22);
        }];
        if(isWhite){
            _rightLbl.textColor = Color_7ACC00;
        }else{
            _rightLbl.textColor = Whire_Color;
        }
        _rightLbl.font = BFont(16);
        _rightLbl.text = rightTitle;
        _rightLbl.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightClick)];
        [_rightLbl addGestureRecognizer:tap];
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (void)rightClick{
    self.rightClickBlock();
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

-(UIView *)navBottomViewTag:(NSInteger)tag{
    if(!_navBottomView){
        _navBottomView = [[NavBottomView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 70, DEVICE_WIDTH, 70)];
        [_navBottomView setCurrentIndex:tag];
        _navBottomView.tabController = self.tabBarController;
    }
    return _navBottomView;
}

- (NSMutableArray *)deviceInfoList{
    if(!_deviceInfoList){
        _deviceInfoList = [NSMutableArray array];
    }
    return _deviceInfoList;
}

@end
